package ore.example.pokemonPb.command;

import com.pixelmonmod.pixelmon.api.pokemon.Pokemon;
import com.pixelmonmod.pixelmon.api.pokemon.PokemonFactory;
import com.pixelmonmod.pixelmon.api.pokemon.species.Species;
import com.pixelmonmod.pixelmon.api.registries.PixelmonSpecies;
import com.pixelmonmod.pixelmon.api.storage.PCStorage;
import com.pixelmonmod.pixelmon.api.storage.StorageProxy;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class GiveGen1PokemonCommand implements CommandExecutor {

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

        if (!(sender instanceof Player player)) {
            sender.sendMessage("§c只有玩家可以使用此命令。");
            return true;
        }

        PCStorage pc = StorageProxy.getPCForPlayerNow(player.getUniqueId());
        int count = 0;

        for (int dexNumber : PixelmonSpecies.getGenerationDex(1)) { // 👈 只获取第 1 世代
            Species species = PixelmonSpecies.fromNationalDex(dexNumber);
            if (species == null) continue;

            Pokemon pokemon = PokemonFactory.create(species);
            if (pokemon == null) continue;

            try {
                if (pc.hasSpace()) {
                    pc.add(pokemon);
                    count++;
                } else break;
            } catch (Exception ignored) {}
        }

        player.sendMessage("§a已为你添加第一世代宝可梦，共计 §e" + count + " §a只。");
        return true;
    }
}
